package com.itheima.service.impl;

import com.itheima.data.Customer;
import com.itheima.data.RiskLevel;
import com.itheima.service.customexception.InformationNullPointer;

/*
业务层
决策支持系统
 */
public class DecisionSupportSystem {

    public void makeLoanApprovalDecision(Customer customer) throws InformationNullPointer {
        if (customer==null){
            throw  new InformationNullPointer("未查询到客户信息");
        }

        // 根据客户的信用评分和风险等级做出贷款审批决策
        // 实现具体的决策逻辑 如果级别是LOW,不予批准
        // 如果是其它：
        // MEIDIUM 客户的收入 * 信用评分/100*50%  HIGH客户的收入 * 信用评分/100*100%

        //信用评分
        CreditScoringModel creditScoringModel = new CreditScoringModel();
        int score = 0;
        try {
            score = creditScoringModel.calculateCreditScore(customer);
        } catch (InformationNullPointer e) {
            System.out.println(e.getMessage());
        }

        //客户收入
        double income = customer.getIncome();

        //评分等级
        RiskClassifier riskClassifier = new RiskClassifier();
        RiskLevel riskLevel = riskClassifier.classifyRisk(score);
        double all = 0.0;
        if (riskLevel == RiskLevel.LOW) {
            System.out.println("经银行考核，您当前不满足办理信用卡的条件！"+"\n");
            return;
        }else  if (income<12000) {  //可贷款金额
            all = income * score / 100 * 0.5;
        }else {
         all=   income*score/100*1;
        }

        //输出决策结果
        System.out.println(customer.getName() + "信用等级: " + riskLevel + ",可贷款金额：" + all+"\n");
    }
}
